$(function(){
	
	// 定义底部保存，清空，取消按钮
	$('#comprehensiveAdd').dialog({
		buttons : [ {
			text : '保存',
			iconCls : 'icon-save',
			handler : function() {
				$('#ffc').form('submit', {
					url:"../exam1/comprehensiveAdd",
					onSubmit : function(param) {
						$.post("../exam1/comprehensiveAdd?qbId="+$("#comprehensive_getTk").val()+"&answer="+$("#c2").val()+"&examQuestion="+$("#c1").val(),function(){
							$('#comprehensive').datagrid('reload');
						})
						$("#comprehensiveAdd").window("close");
					},
					success : function(data) {
					}
				});

			}
		}, {
			text : '清空',
			iconCls : 'icon-clear',
			handler : function() {
				$('#ffc').form('clear');
			}
		}, {
			text : '取消',
			iconCls : 'icon-cancel',
			handler : function() {
				$("#comprehensiveAdd").window("close");
			}
		} ]
	});
	
	
	wjl_editIndex=undefined;
	var url='../exam1/getAllcomprehensive';
	$('#comprehensive').datagrid({
	    url:url,
	    columns:[[
	    	{field:'comprehensiveQuestionId',title:"编号",width:50,align:'center'},
	    	{field:'qb_id',title:"题库",width:50,align:'center',
	    		formatter: function(value,row,index){
					if (row.questionBank){
						return row.questionBank.qbName;
					} else {
						return value;
					}
				}},
			{field:'examQuestion',title:"考题",width:500,align:'center'},
			{field:'answer',title:"答案",width:50,align:'center'},
			{field:'createPeople',title:"创建人",width:80,align:'center'},
			{field:'createDate',title:"创建时间",width:150,align:'center'},
			{field:'',width:100,align:'center',checkbox:true}
	    ]],
		fit:true,
		method:'get',
		toolbar:'#comprehensive_tb',
		rownumbers:true,
		width: 700,
		height: 250,
		//显示分页栏
		pagination:true,
		//设置每页大小
		pageSize:3,
		//可选的每页大小
		pageList:[3,6,10],
		
		});
	
	
	
	
	$("#tK4").combobox({
	    url:'../exam/getAllquestionBank',
	    valueField:'qbId',
	    textField:'qbName'
	});
	$("#comprehensiveSearch").bind('click',function(){
		var qbId=$("#tK4").val();
		var examQuestion=$("#comprehensiveName").val();
		if(qbId==""){
			qbId=0;
		}
		if(examQuestion==""){
			examQuestion="error";
		}
		alert(examQuestion);
		var value=qbId+","+examQuestion;
		$('#comprehensive').datagrid('load',"../exam1/comprehensiveSearch?value="+value);
	})
});

function add(){
	$("#comprehensiveAdd").window("open");
	$('#comprehensive_getTk').combobox({
	    url:'../exam/getAllquestionBank',
	    valueField:'qbId',
	    textField:'qbName'
	});
}


//删除
function remove(){
	var rows = $('#comprehensive').datagrid('getSelections');
	if(rows.length > 0){
		$.messager.confirm('请确认','您确定要删除当前所有选中的项目吗？',function(r){
			if(r){
				var comprehensiveIds = [];
				for(var i = 0; i < rows.length; i++){
					debugger;
					comprehensiveIds.push(rows[i].comprehensiveQuestionId)
					
				}
				$.post('../exam1/deletecomprehensive?value='+comprehensiveIds,function(){
					$('#comprehensive').datagrid('reload');
				})
				wjl_editIndex = undefined;
			}
		})
	}else{
		$.messager.alert('提示','请选择要删除的记录！','error');
	}
}

